package javafx.demo.animation;

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 * 渐变效果
 * 
 * @author flyfox
 * @date 2014年10月23日
 */
public class TestTimelineTransition extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		final Rectangle rectBasicTimeline = new Rectangle(100, 50, 100, 50);
		rectBasicTimeline.setFill(Color.RED);
		
		BorderPane outerRoot = new BorderPane();
		outerRoot.setCenter(rectBasicTimeline);

		Scene scene = new Scene(outerRoot, 600, 500);

		stage.setTitle("Hello World!");
		stage.setScene(scene);
		stage.show();

		final Timeline timeline = new Timeline();
		timeline.setCycleCount(Timeline.INDEFINITE);
		timeline.setAutoReverse(true);
		final KeyValue kv = new KeyValue(rectBasicTimeline.xProperty(), 300);
		final KeyFrame kf = new KeyFrame(Duration.millis(500), kv);
		timeline.getKeyFrames().add(kf);
		timeline.play();
		
	}

	public static void main(String[] args) {
		launch(args);
	}
}
